﻿/*
  Copyright © Alexander G. Bykin, Russia 2010
  This source is subject to the Microsoft Public License (Ms-PL).
  Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  Project link: http://datagridriaex4sl.codeplex.com/
  Related project link: http://riadatafilter.codeplex.com/
  All other rights reserved.
*/

namespace DataGridRIAExtension
{
    using System;
    using System.Windows.Controls;
    using System.Windows.Data;

    //Source found at http://forums.silverlight.net/forums/p/200719/468384.aspx
    public class BindingConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (value.GetType().Name == "Binding")
            {
                ContentControl cc = new ContentControl();
                Binding newValue = value as Binding;
                cc.SetBinding(ContentControl.ContentProperty, newValue as Binding);
                return cc;
            }
            else
            {
                return value;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }
}
